package com.joyoung.control.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.joyoung.common.utils.ClassUtil;


/**
 * AlertDialogBuilder
 *
 */
@SuppressWarnings({"WeakerAccess", "unused"})
public class AlertDialogBuilder implements IAlertDialogBuilder {

    private static Class<? extends IAlertDialogBuilder> sDialogBuilderProxyClass;

    public static void setDialogBuilderProxyClass(Class<? extends IAlertDialogBuilder> dialogBuilderProxyClass) {
        sDialogBuilderProxyClass = dialogBuilderProxyClass;
    }

    public static Class<? extends IAlertDialogBuilder> getDialogBuilderProxyClass() {
        return sDialogBuilderProxyClass;
    }

    private IAlertDialogBuilder mDialogBuilderProxy;

    public AlertDialogBuilder() {
        if (getDialogBuilderProxyClass() != null) {
            mDialogBuilderProxy = ClassUtil.newInstance(getDialogBuilderProxyClass());
        }
    }

    @Override
    public IAlertDialogBuilder context(Context context) {
        mDialogBuilderProxy.context(context);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder title(@NonNull CharSequence title) {
        mDialogBuilderProxy.title(title);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder content(@NonNull CharSequence content) {
        mDialogBuilderProxy.content(content);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder items(@NonNull CharSequence... items) {
        return mDialogBuilderProxy.items(items);
    }

    @Override
    public IAlertDialogBuilder itemsCallback(@NonNull ListCallback callback) {
        return mDialogBuilderProxy.itemsCallback(callback);
    }

    @Override
    public IAlertDialogBuilder positiveText(@NonNull CharSequence positiveText) {
        mDialogBuilderProxy.positiveText(positiveText);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder negativeText(@NonNull CharSequence negativeText) {
        mDialogBuilderProxy.negativeText(negativeText);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder neutralText(@NonNull CharSequence neutralText) {
        mDialogBuilderProxy.neutralText(neutralText);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialog showProgress(Context context, @NonNull CharSequence content) {
        return mDialogBuilderProxy.showProgress(context, content);
    }

    @Override
    public IAlertDialogBuilder autoDismiss(boolean autoDismiss) {
        return mDialogBuilderProxy.autoDismiss(autoDismiss);
    }

    @Override
    public IAlertDialogBuilder onPositive(@NonNull SingleButtonCallback callback) {
        mDialogBuilderProxy.onPositive(callback);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder onNegative(@NonNull SingleButtonCallback callback) {
        mDialogBuilderProxy.onNegative(callback);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder onNeutral(@NonNull SingleButtonCallback callback) {
        mDialogBuilderProxy.onNeutral(callback);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder dismissListener(@NonNull DialogInterface.OnDismissListener listener) {
        return mDialogBuilderProxy.dismissListener(listener);
    }

    @Override
    public IAlertDialogBuilder cancelable(boolean cancelable) {
        mDialogBuilderProxy.cancelable(cancelable);
        return mDialogBuilderProxy;
    }

    @Override
    public IAlertDialogBuilder customView(@LayoutRes int layoutRes, boolean wrapInScrollView) {
        return mDialogBuilderProxy.customView(layoutRes, wrapInScrollView);
    }

    @Override
    public IAlertDialogBuilder inputType(int type) {
        return mDialogBuilderProxy.inputType(type);
    }

    @Override
    public IAlertDialogBuilder input(@Nullable CharSequence hint, @Nullable CharSequence preFill, @NonNull InputCallback callback) {
        return mDialogBuilderProxy.input(hint, preFill, callback);
    }

    @Override
    public IAlertDialog build() {
        return mDialogBuilderProxy.build();
    }

    @Override
    public IAlertDialog show() {
        return mDialogBuilderProxy.show();
    }
}
